#ifndef ATTENDANCEWIDGET_H
#define ATTENDANCEWIDGET_H

#include <QWidget>
#include <QStackedWidget>
#include "../../../Common/models.h"
#include "../../../Common/protocol.h"

class QCheckBox;
class QTableWidget;
class QLineEdit;
class QComboBox;
class QDateEdit;
class QTextEdit;

namespace Ui {
class AttendanceWidget;
}

class AttendanceWidget : public QWidget
{
    Q_OBJECT

public:
    explicit AttendanceWidget(const Doctor& doctor, QWidget *parent = nullptr);
    ~AttendanceWidget();

signals:
    void backToMain();

private slots:
    void onDailyCheckInClicked();
    void onLeaveRequestClicked();
    void onCancelLeaveClicked();
    void onBackClicked();
    
    // 日常打卡
    void onTodayCheckBoxToggled(bool checked);
    void onMessageReceived(MessageType type, const QJsonObject& data);
    void loadAttendanceRecords();
    
    // 请假
    void onSubmitLeaveClicked();
    void onCancelLeaveRequestClicked();
    
    // 销假
    void onLeaveRecordClicked(int row);
    void onCancelLeaveConfirm(int requestId);

private:
    void setupUI();
    void setupDailyCheckInPage();
    void setupLeaveRequestPage();
    void setupCancelLeavePage();
    void updateTodayCheckInStatus();
    
    Ui::AttendanceWidget *ui;
    Doctor m_doctor;
    
    // 三个页面的widget
    QWidget* m_dailyCheckInPage;
    QWidget* m_leaveRequestPage;
    QWidget* m_cancelLeavePage;
    
    // 日常打卡页面控件
    QCheckBox* m_todayCheckBox;
    QTableWidget* m_attendanceTable;
    
    // 请假页面控件
    QLineEdit* m_phoneEdit;
    QComboBox* m_leaveTypeCombo;
    QDateEdit* m_startDateEdit;
    QDateEdit* m_endDateEdit;
    QTextEdit* m_reasonEdit;
    
    // 销假页面控件
    QTableWidget* m_leaveRecordsTable;
    
    QStackedWidget* m_stackedWidget;
    bool m_isCheckedIn;
};

#endif // ATTENDANCEWIDGET_H

